package com.zisuyi.uilibrary.module.dialog

import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope
import com.weilele.mvvm.base.helper.appCompatActivity
import com.weilele.mvvm.utils.activity.gone
import com.weilele.mvvm.utils.activity.textFrom
import com.weilele.mvvm.utils.activity.visible
import com.zisuyi.uilibrary.databinding.DialogSimpleTextBinding

class SimpleTextDialog : BaseTitleDialog<DialogSimpleTextBinding>() {
    companion object {
        fun AppCompatActivity?.simpleTextDialog(l: SimpleTextDialog.() -> Unit) {
            this ?: return
            SimpleTextDialog().apply {
                lifecycleScope.launchWhenCreated {
                    println()
                }
                lifecycleScope.launchWhenStarted {
                    l.invoke(this@apply)
                }
            }.safeShow(appCompatActivity)
        }
    }

    var content: String
        set(value) {
            mBinding.tvContent.textFrom(value)
        }
        get() {
            return mBinding.tvContent.toString()
        }

    var buttonText: String?
        set(value) {
            mBinding.btNext.textFrom(value)
            if (value.isNullOrBlank()) {
                mBinding.btNext.gone()
            } else {
                mBinding.btNext.visible()
            }
        }
        get() {
            return mBinding.btNext.toString()
        }

    val buttonNext: View
        get() = mBinding.btNext
}